home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / pcb121.zip / QIF.INC < prev    next >
Text File  |  1992-01-23  |  8KB  |  248 lines

  1. ;;******************************************************************************
  2. ;;                         qif.inc      qif.inc
  3. ;;******************************************************************************
  4. ;;
  5. ;;  Copyright (C) 1990 Vance Morrison
  6. ;;
  7. ;;
  8. ;; Permission to view, compile, and modify for LOCAL (intra-organization) 
  9. ;; USE ONLY is hereby granted, provided that this copyright and permission 
  10. ;; notice appear on all copies.  Any other use by permission only.
  11. ;;
  12. ;; Vance Morrison makes no representations about the suitability 
  13. ;; of this software for any purpose.  It is provided "as is" without expressed 
  14. ;; or implied warranty.  See the copywrite notice file for complete details.
  15. ;;
  16. ;;******************************************************************************
  17. ;; qif.inc contains the interface driver for a QIF interface.  This
  18. ;; software is responcible for packetizing/depacketizing the data for the
  19. ;; serial line and providing data transparency (byte stuffing)
  20. ;;
  21. ;; The functions provided by this file are
  22. ;;
  23. ;;   Q_IF_DECLARE name, rbuff, rqueue, wbuff, wqueue, prefix, port
  24. ;;   Q_IF_DEFINE name
  25. ;;   Q_IF_R_ACCESS_out_BX_CX_ES name, no_packet
  26. ;;   Q_IF_R_CONT_in_BX_CX_ES_const_BX_CX_DX_BP_SI_DI_ES name, ok
  27. ;;   Q_IF_R_FREE_const_BX_CX_BP_SI_DI_ES name
  28. ;;   Q_IF_W_ACCESS_in_CX_out_DI_ES_const_BX_CX_BP name, no_buffer
  29. ;;   Q_IF_W_WRITE_in_CX_const_BX_BP_ES name
  30. ;;   Q_IF_SET_ADDRESS_in_SI_const_BX_CX_BP_DI_ES name
  31. ;;   Q_IF_COPY_in_CX_SI_DI_ES_out_SI_DI_const_BX_BP_ES name
  32. ;;
  33. ;; Variables set by this module
  34. ;;
  35. ;;   qif_&name&_declared                     ;; one if this interface exists
  36. ;;
  37. ;; Variables used by this module
  38. ;;
  39. ;;   if_&name&_mtu                           ;; the MTU of this interface
  40. ;;
  41. ;;******************************************************************************
  42.  
  43. ;;******************************************************************************
  44. ;; data storage needed by this module
  45.  
  46. qif_entry STRUC
  47.     qif_q_start DW ?
  48.     qif_q_end   DW ?
  49.     qif_q_len   DW ?
  50. qif_entry ENDS
  51.  
  52. qif_data  STRUC
  53.     qif_wpkt_start  DW 0 
  54.     qif_wpkt_end    DW 0
  55. qif_data ENDS
  56.  
  57.  
  58. ;;******************************************************************************
  59. ;;   IF_DECLARE name, rbuff, rqueue, wbuff, wqueue, prefix, port
  60. ;;       rbuff and wbuff are the buffer sizes (in bytes for the read
  61. ;;       and write buffers, and rqueue and wqueue are the number length
  62. ;;   of the queue in packets.  Whenever a high level write is performed
  63. ;;   the routine <prefix>_WRITE_const_BX_BP_ES <port> is called.
  64. ;;
  65. Q_IF_DECLARE MACRO name, rbuff, rqueue, wbuff, wqueue, prefix, port
  66.     .errb <name>
  67.     .errb <irq>
  68.  
  69.     .DATA
  70.     qif_&name&_declared     = 1
  71.  
  72.     qif_&name&_rbuff   = rbuff
  73.     qif_&name&_rqueue  = rqueue
  74.     qif_&name&_wbuff   = wbuff
  75.     qif_&name&_wqueue  = wqueue
  76.     qif_&name&_prefix  equ <prefix>
  77.     qif_&name&_port    = port
  78.  
  79.     global qif_&name&_data:qif_data
  80.     .CODE
  81. ENDM
  82.  
  83.  
  84. ;;******************************************************************************
  85. ;;   IF_DEFINE name
  86. ;;      sets asside memory an name object and initializes it.  This
  87. ;;      routine is a no-op if 'name' was not declared.  
  88. ;;
  89. Q_IF_DEFINE MACRO name
  90. ifdef qif_&name&_declared
  91.     .DATA
  92.     qif_&name&_data    qif_data      <>  
  93.     .CODE
  94. endif
  95. ENDM
  96.  
  97.  
  98. ;;******************************************************************************
  99. ;;   IF_R_ACCESS_out_BX_ES name, no_packet
  100. ;;       IF_R_ACCESS checks for the next packet to come from the the board
  101. ;;       associated with 'name' and returns a pointer to the begining of 
  102. ;;       an ethernet packet in BX:ES.  CX holds the length of the packet
  103. ;;       R_ACCESS jumps to 'no_packet' if there are no packets waiting to 
  104. ;;       be read in
  105. ;;       
  106. Q_IF_R_ACCESS_out_BX_CX_ES MACRO name, no_packet
  107.     .errb <no_packet>
  108.  
  109.     QUEUE_HEAD_out_SI_const_AX_BX_CX_DX_BP_DI_ES %qif_&name&_rqueue, no_packet
  110.     mov BX, [SI+qif_q_start]
  111.     mov CX, [SI+qif_q_len]
  112.     mov AX, DS
  113.     mov ES, AX
  114. ENDM
  115.  
  116.  
  117. ;;******************************************************************************
  118. ;;   IF_R_FREE_const_BX_CX_BP_SI_DI_ES  name
  119. ;;       After the client is through processing the packet returned by 
  120. ;;       IF_R_ACCESS, IF_R_FREE must be called to inform 'name' that the 
  121. ;;       memory that the packet was in can be reused for future packets.
  122. ;;
  123. Q_IF_R_FREE_const_BX_CX_BP_SI_DI_ES MACRO name
  124.     local done
  125.     .errb <name>
  126.  
  127.     cli
  128.     mov AX, SI                  ;; save SI DI
  129.     mov DX, DI
  130.  
  131.     QUEUE_HEAD_out_SI_const_AX_BX_CX_DX_BP_DI_ES %qif_&name&_rqueue, done
  132.     mov DI, [SI+qif_q_end]
  133.     BUFF_FREE_in_DI_const_AX_BX_CX_DX_BP_SI_DI_ES %qif_&name&_rbuff
  134.     QUEUE_DEQUEUE_in_SI_const_AX_BX_CX_DX_BP_DI_ES %qif_&name&_rqueue
  135.     done:
  136.  
  137.     mov SI, AX                  ;; restore SI DI
  138.     mov DI, DX
  139.     sti
  140. ENDM
  141.  
  142.  
  143. ;;******************************************************************************
  144. ;;   Q_IF_R_CONT_in_BX_CX_ES name, ok
  145. ;;       IF_R_CONT determines if the packet returned by R_READ in BX:ES
  146. ;;       of length CX is continuous.  If it is it jumps to 'ok' otherwise
  147. ;;       it just returns
  148. ;;
  149. Q_IF_R_CONT_in_BX_CX_ES_const_BX_CX_DX_BP_SI_DI_ES MACRO name, ok
  150.     .errb <ok>
  151.  
  152.     jmp ok      ;; is it always continuous
  153. ENDM
  154.  
  155.  
  156. ;;******************************************************************************
  157. ;;   IF_W_ACCESS_in_CX_out_DI_ES name, no_buffer
  158. ;;       IF_W_ACCESS returns a pointer to an output buffer for a packet.  The 
  159. ;;       pointer is returned in DI:ES.  If the ouptut buffer is busy, this 
  160. ;;       routine will jump to 'no_buff'.  The output buffer  min(CX, mtu) 
  161. ;;       bytes long
  162. ;;
  163. Q_IF_W_ACCESS_in_CX_out_DI_ES_const_BX_CX_BP MACRO name, no_buff
  164.     local lenOK, done, my_no_buff
  165.     .errb <no_buffer>
  166.  
  167.    cmp CX, if_&name&_mtu
  168.    jbe lenOK
  169.        mov CX, if_&name&_mtu
  170.    lenOK:
  171.    cli
  172.    BUFF_CHECK_in_CX_out_SI_DI_const_BX_CX_DX_BP_ES %qif_&name&_wbuff,my_no_buff
  173.    BUFF_GET_in_DI_const_AX_BX_CX_DX_BP_SI_DI_ES %qif_&name&_wbuff
  174.    sti
  175.    mov word ptr qif_&name&_data.qif_wpkt_start, SI
  176.    mov word ptr qif_&name&_data.qif_wpkt_end, DI
  177.    mov DI, SI
  178.    mov AX, DS
  179.    mov ES, AX
  180.    jmp done
  181.  
  182.    my_no_buff:
  183.        sti
  184.        jmp no_buff
  185.  
  186.    done:
  187. ENDM
  188.  
  189.  
  190. ;;******************************************************************************
  191. ;;   IF_W_WRITE_in_CX name
  192. ;;       IF_W_WRITE actually signals the ethernet board to write a packet to 
  193. ;;       the ethernet.  The packet is assumed to be in the buffer returned by 
  194. ;;       IF_W_ACCESS. CX is the length of the packet to send.  
  195. ;;
  196. Q_IF_W_WRITE_in_CX_const_BX_BP_ES MACRO name
  197.     local done
  198.     .errb <name>
  199.  
  200.    cli
  201.    QUEUE_ENQUEUE_out_DI_const_BX_CX_DX_BP_SI_ES %qif_&name&_wqueue, done
  202.    mov AX, word ptr qif_&name&_data.qif_wpkt_start
  203.    mov [DI+qif_q_start], AX
  204.    mov AX, word ptr qif_&name&_data.qif_wpkt_end
  205.    mov [DI+qif_q_end], AX
  206.    mov [DI+qif_q_len], CX
  207.         ;start the low level processing, if necessary.
  208.    done:
  209.    CALL_WRITE_const_BX_BP_ES %qif_&name&_prefix, %qif_&name&_port
  210.    sti
  211.  
  212. ENDM
  213.  
  214. CALL_WRITE_const_BX_BP_ES MACRO prefix, port
  215.    prefix&_WRITE_const_BX_BP_ES port
  216. ENDM
  217.  
  218.  
  219. ;;******************************************************************************
  220. ;;   IF_SET_ADDRESS_in_SI name
  221. ;;       IF_SET_ADDRESS_in_SI sets the hardware address to be the value
  222. ;;       pointed to by SI.  Note this function may be a no-op if the
  223. ;;       hardware address cannot be set (ETHERNET for example)
  224. ;;
  225.  
  226. Q_IF_SET_ADDRESS_in_SI_const_BX_CX_BP_DI_ES MACRO name
  227.     .err    ;; we don't support setting ethernet addresses 
  228.     ENDM
  229.  
  230.  
  231. ;;******************************************************************************
  232. ;;   IF_COPY_in_CX_SI_DI_ES_out_SI_DI name
  233. ;;      IF_COPY_in_CX_SI_DI_ES copys a packet from the input buffer (pointed 
  234. ;;      to by SI and the segement register given in IF_DECLARE) to an output 
  235. ;;      buffer (pointed to by DI and ES) of length CX.   It assumes the
  236. ;;      output buffer is contiguous.  (and the caller shouln't care if the 
  237. ;;      input buffer is contiguous)
  238. ;;
  239. Q_IF_COPY_in_CX_SI_DI_ES_out_SI_DI_const_BX_BP_ES MACRO name
  240.     .errb <name>
  241.  
  242.     ;; since DS points to the data segment, we are ready to go!!
  243.     inc CX
  244.     shr CX,1
  245.     rep movsw
  246. ENDM
  247.  
  248.